import {type Ref, ref} from 'vue'
import {defineStore} from 'pinia'
import type {MenuTypes} from '@/resources/interface/sys/MenuTypes'

export const useAccountStore = defineStore('account', () => {
    const account = ref('')
    const saveAccount = (value: string) => {
        account.value = value;
    }
    const clearAccount = () => {
        account.value = '';
    }

    return {account, saveAccount,clearAccount}
}, {
    persist: true
})

export const useTokenStore = defineStore(
    'token',
    () => {
        const token = ref('')
        const setToken = (value: string) => {
            token.value = value
        }
        const getToken = () => {
            return token.value
        }
        const hasToken = () => {
            return token.value != ''
        }
        const clearToken = () => {
            token.value = ''
        }
        return {token, setToken, getToken, hasToken, clearToken}
    },
    {
        persist: true
    }
)

export const useMenuListStore = defineStore(
    'menuList',
    () => {
        const menuList: Ref<MenuTypes[]> = ref([])
        const saveMenuList = (value: any) => {
            menuList.value = value
        }
        const clearMenuList = () => {
            menuList.value = []
        }
        return {menuList, saveMenuList, clearMenuList}
    },
    {
        persist: true
    }
)
